package com.hao.spring.factoryBean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.Nullable;

/**
 * TODO
 *
 * @author 97472
 * @version 1.0
 * @date 2021/11/2 17:26
 */
public class Dept implements BeanNameAware , BeanFactoryAware , ApplicationContextAware , BeanPostProcessor {

    private String name;

    public Dept() {
        System.out.println("bean生命周期第一步启动容器，创建实例化对象");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        System.out.println("bean生命周期第二步，注入属性");
    }

    public void setBeanName(String s) {
        System.out.println("bean生命周期第三步，将调用setBeanName将id传入"+s);
    }

    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("bean生命周期第四步，将调用setBeanFactory传入beanFactory"+beanFactory);
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("bean生命周期第五步，将调用setApplicationContext传入applicationContext"+applicationContext);
    }

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("bean生命周期第六步，Spring就将调用他们的postProcessBeforeInitialization()方法。");
        return null;
    }

    public void init(){
        System.out.println("bean生命周期第七步，调用init方法");
    }

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("bean生命周期第八步，Spring就将调用他们的postProcessAfterInitialization()方法。");
        return null;
    }

    public void destroy(){
        System.out.println("bean生命周期十步，Spring在退出容器中就将调用他们的destroy()方法。");
    }
}
